﻿package org.hsl.avm2.translation.error;
import flash.events.ErrorEvent;
import org.hsl.haxe.translation.ITranslator;
import org.hsl.haxe.translation.NativeEvent;
/**
 * A translator that translates error events to strings containing the error message.
 */
// Ideally, the following line would be:
// class ErrorMessageTranslator implements ITranslator<String> {
// However, that doesn't work targeting AVM2.
class ErrorMessageTranslator<D> implements ITranslator<D> {
	/**
	 * Creates a new error message translator.
	 */
	public function new():Void {
	}
	public function translate(nativeEvent:NativeEvent):D {
		var errorEvent:ErrorEvent;
		try {
			errorEvent = cast(nativeEvent, ErrorEvent);
		} catch (error:Dynamic) {
			throw "The nativeEvent argument must be an ErrorEvent.";
		}
		return untyped errorEvent.text;
	}
}